#include "stdafx.h"
#include "tile_image.hpp"
#include <fstream>

namespace FndGame2D {
  bool tile_image::read_rects_from_file(const char* file_name) {
    pantheios::log_INFORMATIONAL("tile_image load rects from file: ", file_name , "\n") ;
    std::fstream fin(file_name) ;
    if(!fin) {
      pantheios::log_WARNING("could not open file: ", file_name) ;
      return false ;
    }
    try {
      while(fin) {
	std::string rect_name ;
	sf::IntRect rect ;
	unsigned int w ;
	unsigned int h ;
	fin >> rect_name >> rect.Left  >> rect.Top >> w >> h ;
	rect.Right = w + rect.Left ;
	rect.Bottom = h + rect.Top ;
	add_rect(rect_name, rect) ;
      }
    } catch(std::exception& e) {
      pantheios::log_ERROR("ex when load file ", e,"\n") ;
      return false ;
    }
    fin.close() ;
    return true ;
  }
}
